package com.gitee.wsl.mathematics.interpolator.ext

import com.gitee.wsl.ext.number.clamp
import com.gitee.wsl.ext.number.clamp01
import com.gitee.wsl.mathematics.interpolator.Ratio

val Float.ratio: Float
    get() = clamp(0.0f,1.0f)

val Double.ratio: Double
    get() = clamp(0.0,1.0)

inline fun Number.toRatio(): Ratio = Ratio(this.toDouble())
fun Float.toRatio(): Ratio = Ratio(this)
fun Double.toRatio(): Ratio = Ratio(this)

inline fun Number.toRatio(max: Number): Ratio = Ratio(this.toDouble(), max.toDouble())
fun Float.toRatio(max: Float): Ratio = Ratio(this, max)
fun Double.toRatio(max: Double): Ratio = Ratio(this, max)

fun Number.toRatioClamped(): Ratio = Ratio(this.toDouble().clamp01())
fun Float.toRatioClamped(): Ratio = Ratio(this.clamp01())
fun Double.toRatioClamped(): Ratio = Ratio(this.clamp01())
